package edu.ynu.e_platform.entities;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import edu.ynu.e_platform.common.entity.LogicEntity;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @author manwen Yang
 */
@Entity
@Getter
@Setter
@JsonIgnoreProperties(value = {"handler","hibernateLazyInitializer","fieldHandler"})
@Where(clause = "isDeleted = 0")  //逻辑删除,过滤掉删除标记不为0的
public class LineItem extends LogicEntity {

    @Column
    private Double quantity;

    @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnoreProperties(value = {"lineItems", "customer", "shop"})
    private Order order;

    @OneToOne(fetch = FetchType.LAZY)
    @JsonIgnoreProperties(value = {"lineItem","business","shopItems"})
    private Item item;

    /**
     *  计算单种商品的总价
     * @return 总价
     */
    @JsonIgnore
    public Double getItemTotlePrice(){
        return quantity*item.getPrice();
    }
}
